/*
 * Time : 2022/12/3 19:16
 * Auth : weixinlong
 * Email : weixinlong@buaa.edu.cn
 * File : hash.go
 */

package util

import (
	"golang.org/x/crypto/bcrypt"
)

func HashPassword(password string) (string, error) {
	bytes, err := bcrypt.GenerateFromPassword([]byte(password), 10)
	return string(bytes), err
}

func CheckPasswordHash(password, hash string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
	return err == nil
}
